<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/29
 * Time: 14:03
 */

namespace App\Http\Controllers\MiniProgram;
use App\Http\Logics\MiniProgram\CashCouponLogic;
use App\Http\Traits\CashCouponTrait;
use App\Http\Controllers\BaseController;
class CashCouponController extends BaseController
{
    use CashCouponTrait;

    /**
     * @SWG\Get(
     *     path="/cashCoupon/list",
     *     tags={"CashCoupon"},
     *     description="获取代金券列表",
     *     operationId="getCashCouponList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="key",
     *         in="query",
     *         description="合作者key",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCashCouponList()
    {
        $loginSession = $this->loginSession;
        $key = $this->key;
        $data = [
            'key' => $key,
            'loginSession' => $loginSession
        ];
        $response = CashCouponLogic::getCashCouponList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }


    /**
     * @SWG\Get(
     *     path="/cashCoupon/createPoster",
     *     tags={"CashCoupon"},
     *     description="创建代金券的分享海报",
     *     operationId="createCashCouponPoster",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="page",
     *         in="query",
     *         description="小程序页面路径",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createCashCouponPoster()
    {
        $page = $this->page;
        $cash_coupon_id = $this->cash_coupon_id;
        $data = [
            'page' => $page,
            'cash_coupon_id' => $cash_coupon_id
        ];
        $response = CashCouponLogic::createCashCouponPoster($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/cashCoupon/detail",
     *     tags={"CashCoupon"},
     *     description="代金券详情",
     *     operationId="getCashCouponDetail",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCashCouponDetail()
    {
        $cash_coupon_id = $this->cash_coupon_id;
        $data = [
            'cash_coupon_id' => $cash_coupon_id
        ];
        $response = CashCouponLogic::getCashCouponDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}